package cluster

import akka.actor.{Actor, ActorRef, ActorSystem, Props}
import com.typesafe.config.ConfigFactory
import spark.woker.SparkWoker
import spark.woker.SparkWoker.{clientHost, clientPort, contextName, serverHost, serverName, serverPort}

/**
 * @Description: TODO
 * @Author: DJJ
 * @Date: 2019/12/13 10:18
 */
class ClusterTest extends Actor {
  override def receive: Receive = {
    case "hello"=>
      println("succe")
      println(sender())
    case "start"=>
      println("开始")
  }
}
object ClusterTest extends App{
  val config = ConfigFactory.parseString(
    s"""
       |akka.actor.provider="akka.remote.RemoteActorRefProvider"
       |akka.remote.netty.tcp.hostname="127.0.0.1"
       |akka.remote.netty.tcp.port=9993
        """.stripMargin)

  val sparkWoker = ActorSystem("ClusterTest", config)
  val woker: ActorRef = sparkWoker.actorOf(Props[ClusterTest],"ClusterTest")
  woker ! "start"
  ClusterUtils.getActorRefAndSend("/user/Cluster","akka.tcp://ClusterTest@127.0.0.1:9993/user/ClusterTest")

  Thread.sleep(10000)
  ClusterUtils.getActorRefAndSend("/user/Cluster","akka.tcp://ClusterTest@127.0.0.1:9993/user/ClusterTest")
}
